<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>转账</title>
</head>
<body>
    私钥:<br>
<textarea rows="5" cols="60" id="pri"></textarea><br>
    公钥:<br>
<textarea rows="5" cols="60" id="pub"></textarea><br>
    转账给:<br>
<textarea rows="5" cols="60" id="to"></textarea><br>
    转账信息:<br>
<textarea rows="5" cols="60" id="content">张三给王五转账5毛钱</textarea><br>
<input type="button" value="开始转账" onclick="tranaction()">

<script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/hashes.min.js"></script>
    <script src="js/jsrsasign-all-min.js"></script>
<script type="text/javascript">
    var publicStr = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn0nlLcOd1d+45w+C7sV9mchZDkpI2S0x\n" +
        "fh0uQbp1ug7JSIG0D55NXJ7bFNno0NTNrzOFW4bDx6UvXS3UDfo+Iw/DJ+Mgg7ROk0VZ7OLADl/l\n" +
        "l2deu6Sp//ElHprcpxBX+dFKaf1wuhyIPFMB727MxkENbClWXOzVs36i+YiEp8QdGQYBoZ9I6yAo\n" +
        "hzUbKZzYOt63gTtqrmK58BuLLpcK364VlwUhSrUheLvQGbUL36ejXBJ0P4oLgSqqTrKQ2+ujZ6Ki\n" +
        "/HhBpj/ks2sdtmbVRJmJ0O7j2FJdy+oem2JXI8Pql3Si+FPil8nTD1G4EANdKvAgsULnRAcO9K+w\n" +
        "95QIwwIDAQAB"

    var privateStr = "-----BEGIN PRIVATE KEY-----\n"+
        "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCfSeUtw53V37jnD4LuxX2ZyFkO\n" +
        "SkjZLTF+HS5BunW6DslIgbQPnk1cntsU2ejQ1M2vM4VbhsPHpS9dLdQN+j4jD8Mn4yCDtE6TRVns\n" +
        "4sAOX+WXZ167pKn/8SUemtynEFf50Upp/XC6HIg8UwHvbszGQQ1sKVZc7NWzfqL5iISnxB0ZBgGh\n" +
        "n0jrICiHNRspnNg63reBO2quYrnwG4sulwrfrhWXBSFKtSF4u9AZtQvfp6NcEnQ/iguBKqpOspDb\n" +
        "66NnoqL8eEGmP+Szax22ZtVEmYnQ7uPYUl3L6h6bYlcjw+qXdKL4U+KXydMPUbgQA10q8CCxQudE\n" +
        "Bw70r7D3lAjDAgMBAAECggEAEd3hBfQWJSI2BDzaK9wdDX3Kd27fovSNw56UTK0UfW0hKK/buZDB\n" +
        "Dq2G11zl316vP4Kg57ZDCYa+vE3ipjq2c4pWEohIYl18Hsq9nnOEpVgeUZA3sQZ0RxAOYNNwApEz\n" +
        "vQK7vQ2/cjC3G0UYR3n/IBG15rbwR/YMtlhzAVhNwN9x2cykGojymOcSRoaNJ/361JYoZwzZ6hnw\n" +
        "xnYQ97tXCEzQkllcib9oNvGD0x3eAJk/4wy/0sEaHhxKZQh2NdXXCwT//JP2p/b82E9Jl09ZgLGC\n" +
        "mPlNHJvXmU/LzyJBoCeJh8dTIFa5B5nGHud34oweHJ9VhmeO1cEeL5QQ+s9n+QKBgQDklXCvkpR7\n" +
        "oNyagRMwk5H1WAgVAH4oBpxw1rWu+P3Qr+BLXqQy14nT39HhGpW3oVDD5NaTsY1l2SUgL6cWbnWB\n" +
        "4EtgwLS4K2bMwlPzWLs9g27OS7LtE0HbVKlZyMv1FBzpg2l00ePMAEW/Rx6mwmavOrMyfcJdJceP\n" +
        "3zlMob3r3QKBgQCyZMfa81HOTiQZ9zLRUaQfkRG7x1sfzAhabZxYwFTWvQ9nsa1Xg4ELRydWpjCH\n" +
        "UNuKPPL+EaD08iZ3cZXmYBY6BAN4FoCqHROAgu8M4gr8Sxvr8ggbMzfa2Mjcin87kKOjG+JnPYg+\n" +
        "fYIjAwiWlCIJd9Tv85hRGTM0iJ7fy39NHwKBgE8QEWXpAUqxnRwjwQtwP2/o/wKkpP4bK0ksOrNG\n" +
        "lCP2cVIgbhLX0mhiZinCFD7roQ/guwdixlGQBfNYCCcOFb7SYcAZZ2i8OlZgcMEe08S3DUB1lnHB\n" +
        "02mVou3XMhSW3Fk4huVNI8mP3pAGfWeYngPF/e1c6jlls9zjjOIgn5xRAoGAB6QHZ1pam6J/K1mK\n" +
        "JKsBg5ScFNXiEkeT6AOf2bFLMPNiEIfsq73nLgt7JNvzYihVbuNTaQxqP3OLsDv+NqLQ8OUxHNih\n" +
        "5CdgqXVyNbQM0meJJ57zN+8Gqmn0mHWaI3v7dkYAeXmKN1r60vMTUBfCKXOnfCuLz5VruwlK/Lzj\n" +
        "k/MCgYBKPotVvu3Lo+pHnHxOqTrGp2I8Gx+Im1Uo51lmDlvUFGSR59NZggadrF9qpcB12blw5rFw\n" +
        "lDHj1NI3Ig0vPwG/lKIdPYYnLengKGGPSeJPYM0yw6nTn9JOoyJ25dVbz3Fhw1HhtYQchSthDVt+\n" +
        "Yyd2imrk32K/xNiVEfCwc1+F5w=="+
            "-----END PRIVATE KEY-----"

    var toPublicStr = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAg2V+DYbFTGWnL/xrU8dCyENmA/wLO7k8\n" +
        "8e6SaN1VBKHUozhoNet0y+4lvrGe7lV7ParmwhFIqBd0gKvOd3w+PXtMF0p3XsB5PNtcWr4kgHVB\n" +
        "4437XRPD1/SeySc37EM3oQ11qQWMzAdA1i/D+Qb51mqjVXyMEFRnNm5Vv2H2L82KwE1YwjFjtsOr\n" +
        "pUfjvv9DmeRvLCaFqTPG/gPTN3K6N0L5il9soAF1F5J+uhMs5knsAoEOhiLVIrwcFrcRuVJyhMbt\n" +
        "7bKaQSrByFpeJAB2HRZrJjAlMhAxGY46hI+pIKBs4fPJI6fmfbj62c/PTNhATDyI6UB07HhpvwdT\n" +
        "NDXGywIDAQAB"

    //把文本区域内容填充
    $("#pri").val(privateStr)
    $("#pub").val(publicStr)
    $("#to").val(toPublicStr)

    //提交按钮点击
    function tranaction(e) {
        //私钥
        var privateKey = $("#pri").val()
        //公钥
        var publicKey = $("#pub").val()
        //转账账户
        var toPublicKey = $("#to").val()

        //1.获取转账信息
        var content = $("#content").val()


        var prvKey = KEYUTIL.getKey(privateKey);
        var sig = new KJUR.crypto.Signature({"alg": "SHA256withRSA"});
        sig.init(prvKey);
        sig.updateString(content)
        var sigValueHex = sig.sign()
        console.log(sigValueHex)


        //准备好传输数据
        var transaction = {"content":content,"encrypted":sigValueHex,"publicKey":publicKey,"toPublicKey":toPublicKey};
        //转换为json字符串
        var transMsg = JSON.stringify(transaction)
        // console.log(transMsg)

        //4.发送转账请求(ajax)
        $.ajax({
            method:"POST",
            url:"http://localhost:71/addTransaction",
            data:transMsg,
            success: function(){
                console.log("发送成功")
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("发送失败")
            }
        });
    }
</script>

</body>
</html>